//****************************
//** CImageHigh
//**
//** An image class using IMGDECMP.DLL for decompression.
//**
//****************************

#include "stdafx.h"
#include "CImageHigh.h"
#include "VOImage.h"


CImageHigh::CImageHigh(HDC hdc)
{
    m_hScreenDC = hdc;
	m_hSourceBitmap = NULL;
}

CImageHigh::~CImageHigh()
{
    
	if (m_hSourceDC != NULL) 
    {
		DWORD iRetVal;
        SelectObject(m_hSourceDC, m_hOldBitmap);
		// *ACK* Added 12/12/01
		iRetVal = DeleteObject(m_hSourceBitmap);
		if (iRetVal==0)
			iRetVal = GetLastError();
        iRetVal = DeleteObject(m_hOldBitmap);
	    iRetVal = DeleteDC(m_hSourceDC);

		iRetVal=0;
    }



}

BOOL CImageHigh::Create(int Width, int Height)
{
	// Create the DC
    //HBITMAP hSourceBitmap;

    m_hSourceDC = CreateCompatibleDC(GetScreenDC());
    if (m_hSourceDC == NULL)
        return FALSE;

    m_hSourceBitmap = CreateCompatibleBitmap(GetScreenDC(), Width, Height);
    if (m_hSourceBitmap == NULL)
        return FALSE;

    m_hOldBitmap = SelectBitmap(m_hSourceDC, m_hSourceBitmap);
    if (m_hOldBitmap == NULL)
        return FALSE;

	

    DeleteObject(m_hSourceBitmap);
    return TRUE;
}


BOOL CImageHigh::Load(LPTSTR lpFilename)
{
	// Load the image data from a file
	// using IMGDECMP.DLL

    LPBYTE lpSourceBits;
    DWORD dwSourceBitsSize;
    LPBITMAPINFO lpSrcDIB;

	SetFilename(lpFilename);

	m_hSourceDC = CreateCompatibleDC(GetScreenDC());

	CVOImage *oImage;
	oImage = new CVOImage;
	if (!oImage->Load(m_hSourceDC, lpFilename))
		return FALSE;


	m_iWidth=oImage->GetWidth();
	m_iHeight=oImage->GetHeight();

    m_hSourceBitmap = CreateCompatibleBitmap(GetScreenDC(), m_iWidth, m_iHeight);
    if (m_hSourceBitmap == NULL)
        return FALSE;

    m_hOldBitmap = SelectBitmap(m_hSourceDC, m_hSourceBitmap);
    if (m_hOldBitmap == NULL)
        return FALSE;
	

	oImage->Draw(m_hSourceDC,0,0);

    //store bitmap header into bmBitmap
    //GetObject(hSourceBitmap, sizeof(BITMAP), &m_bmBitmap);

	
	delete oImage;

    return TRUE;
}



BOOL CImageHigh::BitBlit(int x, int y)
{
	// copy image data to the default DC
	return BitBlt(GetScreenDC(), x, y, ImageWidth(), ImageHeight(), m_hSourceDC, 0, 0, SRCCOPY);
}


BOOL CImageHigh::BitBlit(HDC hdc, int x, int y)
{
	// copy image data to a specific DC
	return BitBlt(hdc, x, y, ImageWidth(), ImageHeight(), m_hSourceDC, 0, 0, SRCCOPY);
}


BOOL CImageHigh::TransBlit(int x, int y, COLORREF clrTrans)
{
	// copy image data to a the default DC transparently
    return TransparentImage(GetScreenDC(), x, y, ImageWidth(), ImageHeight(), m_hSourceDC, 0, 0, 
                ImageWidth(), ImageHeight(), clrTrans);
}


BOOL CImageHigh::StretchBlit(int x, int y, int dx, int dy)
{
	// copy and scale image data to a the default DC
	return StretchBlt(GetScreenDC(), x, y, dx, dy, m_hSourceDC, 0, 0, ImageWidth(), ImageHeight(), SRCCOPY);
}


int CImageHigh::ImageWidth()
{
	// return the width of the image
    return m_iWidth; 
}

int CImageHigh::ImageHeight()
{
	// return the height of the image
    return m_iHeight; //(int)((LPBITMAPINFOHEADER) lpDIB)->biHeight;
}

